package haemers.reflection.tests 
{
	import nl.haemers.data.constants.DataTypes;
	import nl.haemers.data.reflection.Parameter;
	import nl.haemers.data.reflection.Type;
	import org.flexunit.Assert;
	/**
	 * ...
	 * @author Jonathan
	 */
	public class ParameterTest 
	{
		private var _idParam:Parameter;
		private var _nameParam:Parameter;
		private var _collectionParam:Parameter;
		
		/** Public methods **/
		[Before]
		public function setup() : void
		{
			_idParam = new Parameter(_idXML, "id");
			_nameParam = new Parameter(_nameXML, "name");
			_collectionParam = new Parameter(_collectionXML, "collection");
		}
		
		[Test]
		public function testBasicParameter() : void
		{
			Assert.assertEquals(DataTypes.NUMBER, _idParam.dataType);
			Assert.assertEquals(1, _idParam.index);
			Assert.assertEquals("id", _idParam.name, _idParam.toString());
			Assert.assertFalse(_idParam.optional);
			Assert.assertNull(_idParam.objectType);
			
			Assert.assertEquals(2, _nameParam.index);
		}
		
		[Test]
		public function testOptional() : void
		{
			Assert.assertTrue(_nameParam.optional);
		}
		
		[Test]
		public function testCollection() : void
		{
			Assert.assertEquals(DataTypes.ARRAY, _collectionParam.dataType);
			Assert.assertNotNull(_collectionParam.objectType);
			Assert.assertTrue(_collectionParam.objectType is Type);
		}
		
		[After]
		public function teardown() : void
		{
			_idParam = null;
			_nameParam = null;
			_collectionParam = null;
			
			_idXML = null;
			_nameXML = null;
			_collectionXML = null;
		}
		
		/** Getters & Setters **/
		
		/** Protected methods **/
		
		/** Private methods **/
		
		private var _idXML:XML = new XML(<parameter index="1" type="Number" optional="false"/>);
		private var _nameXML:XML = new XML(<parameter index="2" type="String" optional="true"/>);
		private var _collectionXML:XML = new XML(<parameter index="1" type="Array" optional="false"/>);
	}
}